<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<!DOCTYPE HTML>
<html>
<head>
<title>My JSP 'main.jsp' starting page</title>

<link href="img/ico.ico" rel="shortcut icon">

<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<script type="text/javascript" src="js/jquery-min.js"></script>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
body {
	background-image: url("img/.png");
}

.addQues {
	padding-top: 60px;
	padding-left: 20%;
	padding-bottom: 10px;
}

.ansOfQues {
	padding-left: 20%;
}

.searchQues {
	padding-left: 20%;
}

.forUser {
	margin-top: 10px;
	float: right;
	padding-right: 25%;
	font-size: 16px;
	font-family: 华文中宋;
}

.searchForm {
	margin-bottom: 0px;
}

.otherA {
	padding-left: 25%;
}

.passAns {
	padding-left: 60px;
}

.pageNum {
	padding-left: 20%;
}

#fileType {
	position: absolute;
	top: 120px;
	width: 240px;
}
.trends{
	position: absolute;
	margin-top: 120px;
	margin-left: 0;
	right:100px;
	left:75%;
	background-color: #fff	;
}

#questionAndAnswer {
	margin-top: 10px;
	width: 90%;
}
</style>

</head>
<body>
	<div class="forUser">
		<c:if test="${empty user }">
			<a href="login.action?task=login" title="点击登录">登陆我的账户</a>
			<span style="float: right;" id="timer"></span>
		</c:if>
		<c:if test="${not empty user}">
		欢迎您,<i class="icon-user"></i><span style="font-family: 方正舒体;">${user.username}</span>
			<a href="setUser.action?userId=${user.id}"><i class="icon-cog"></i>账号设置</a>
			<i class="icon-share-alt"></i><a href="logout.action">退出</a>
			<i class="icon-time"></i><span style="float: right;" id="timer"></span>
		</c:if>
	</div>
	<div id="fileType">
		<h2><i style="margin-top: 9px;" class="icon-folder-open"></i>&nbsp;&nbsp;相关文件</h2>
		<span style="color:#999">全部展开/折叠<span class="openOrExpansion" style="cursor: pointer;color:#000;">┗</span></span>
		<c:forEach var="questionTypes" items="${questionTypesList}" varStatus="status">
			<div class="questionT" id="questiontypes${questionTypes.id}">
				<input type="hidden" value="${questionTypes.id}"/>
				类型${status.count}:
				<a class="expansionBtn" title="点击展开" 
					id="expansionTypeBtn${questionTypes.id}" href="javascript:viod(0)">＋</a>
				<a class="intoQuestionType" title="点击进入问题类型页" href="gotoquestiontype.action?questionTypesId=${questionTypes.id}">${questionTypes.name}</a><br/>
				<div class="fileses" id="questionOf${questionTypes.id}" style="display: none;">
					<c:if test="${empty questionTypes.filesList}">^_^还没有相关文件</c:if>
					<c:forEach var="files" items="${questionTypes.filesList}" varStatus="status" begin="0" step="1" end="9">
					
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<i class="icon-file"></i>${status.count}:<a href="gotoPreviewPage.action?fileId=${files.id}">${files.filename}</a>
						<br/>
						<c:if test="${status.count==10}">
							<c:if test="${questionTypes.size>10}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;未完
							
							<a href="gotoquestiontype.action?questionTypesId=${questionTypes.id}">…</a></c:if>
						</c:if>	
					</c:forEach>
					<%--<c:if test="${not empty questionTypes.questions}">
						<c:forEach var="question" items="${questionTypes.questions}">
							<c:forEach var="files" items="${question.questionFilesRels}" varStatus="status">
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i class="icon-file"></i>:${files.files.filename}<br/>
							</c:forEach>
						</c:forEach>
					</c:if>
				--%>
				</div>
			</div>
			
			
			<%--<span style="cursor: pointer;" class="filetypeName"
				id="firstStackFiletype${questionTypes.id}"> ┣<input type="hidden"
				value="${questionTypes.id}" />
			</span>${questionTypes.name}<br />
			<div id="secondstack${questionTypes.id}" style="display: none" >
				<c:if test="${empty questionTypes.name}">
					&nbsp;&nbsp;&nbsp;暂时还没有文件	
				</c:if>
				<c:if test="${not empty questionTypes.questions}">
					&nbsp;&nbsp;&nbsp;
				长度为:${fileType.size}
				<c:forEach var="file" items="${fileType.fileses}" varStatus="status" begin="0" end="9" step="1">
				
						
						&nbsp;&nbsp;&nbsp;${status.count},
						<a href="gotoPreviewPage.action?fileId=${file.id}">${file.filename}</a>
						<c:if test="${status.count==10}">
							<br/><c:if test="${fileType.size>10}">未完....</c:if>
						</c:if>
						
					<br />
				</c:forEach>
				</c:if>
				<br />
			</div>
		--%></c:forEach>
	</div>
		<div class="trends">
			<c:if test="${not empty user&&(user.role=='sales'||user.role=='admin')}">
				<i class="icon-envelope"></i><a href="#">我的动态</a><%--去动态页面 --%><br/>
				<c:if test="${empty salesQuestionTrendsList }">
					<br/><span>您还没参与问题的提问,O(∩_∩)O~</span>
				</c:if>
				<c:forEach var="question" items="${salesQuestionTrendsList}" begin="0" step="1" end="9">
					&nbsp;&nbsp;&nbsp;<i class="icon-list-alt"></i><a href="oneQuestion.action?questionId=${question.id }">${question.questionname}</a><br/>
					<span style="padding-left:50%">---${question.outtime}</span><br/>
				</c:forEach>
			</c:if>
		</div>
	
	<div id="questionAndAnswer">
		<div class="addQues">
			<h2 style="font-family: 方正静蕾体; padding-left: 100px; color: #605A60;">销售-临床研究部(内部沟通系统)</h2>
			<br/>
			<i class="icon-question-sign"></i><a class="askQuestion"
				href="javascript:void(0)" onclick="getVerifyUser()">提问新问题</a> <span
				class="logintishi"></span>

			<c:if test="${not empty user&&user.role=='sales'}">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;我要<a href="toReserLecturePage.action">约课</a>
			</c:if>
			<c:if test="${not empty user&&user.role=='admin'}">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="toReserLecturePage.action">约课</a>
			</c:if>
		</div>
		<div class="searchQues">
			<form class="searchForm" action="searchQuestion.action">
				<input type="text" name="searchQuestion" style="color: #9B9B9B"
					value="请输入关键词" /><span style="color: #bbb;">多个关键字空格隔开</span>
			</form>
			<a class="btn searchButton" href="#"><i class="icon-search"></i>搜索问题</a><span class="nullOfTishi"></span>
		</div>
		<%-----------分页部分---------------%>
		<br />
		<div class="pageNum">
			<input id="nowpage" type="hidden" style="display: none"
				value="${nowPage} " />

			<c:if test="${totalcount!=0 }">
				<c:if test="${not empty totalcount}">
					<span style="color: #999999;">找到相关的结果${totalcount}条,${maxPage}页,搜索共耗时：${time}秒</span>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			</c:if>
				<div class="pagination">
					<ul>
						<li><a id="firstpage" rel="0" href="javascript:void(0)">首页</a>
						</li>
						<li><a id="before" href="javascript:void(0)">上一页</a></li>
						<c:forEach var="pagenum" items="${pagenum}">
							<li><a class="pagenum" rel="${pagenum}"
								href="javascript:void(0)">${pagenum}</a></li>
						</c:forEach>
						<li><a id="next" href="javascript:void(0)">下一页</a></li>
						<li><a id="lastpage" rel="${maxPage-1}"
							href="javascript:void(0)">尾页</a></li>
					</ul>
				</div>
			</c:if>
		</div>
		<%-------------------------------分页------------------------ --%>
		<div class="ansOfQues">
			<c:if test="${empty questionsList}">
		  	O(∩_∩)O~暂时还没有任何问题！！！
		</c:if>
			<c:forEach var="question" items="${questionsList}" varStatus="status">
				<i class="icon-th-list"></i>
				问题:${status.count}&nbsp;&nbsp;
				<c:if test="${not empty question.answerses}">
					<a href="oneQuestion.action?questionId=${question.id }">${question.questionname}</a>
				</c:if>
				<c:if test="${empty question.answerses&&empty question.questionFilesRels}">
					<a style="color: red;" title="问题还没回答" href="oneQuestion.action?questionId=${question.id }">${question.questionname}</a>
				</c:if>
					<span style="color:#bbb">------${question.user.username}于${question.outtime}</span>
					<c:if test="${user.role=='admin'}">
						<i class="icon-trash"></i>
						<a class="delQuestionById" id="delQuest${question.id}">删除
							<input type="hidden" class="hiddenQuestionId" value="${question.id}"/>
						</a>
				</c:if>
				<c:if test="${not empty question.answerses}">
					<c:forEach var="answer" items="${question.answerses}">
						<div class="passAns" id="passA${question.id}">
							<c:if test="${answer.state=='审核通过'}">
								<span>${answer.content}</span>→→→→→→答案<span>${answer.state}</span>
								<br />
							</c:if>
						</div>
					</c:forEach>
					<div class="stackOne" id="otherAnswer${question.id}"
						style="cursor: pointer; color: #3A3AD8; width:120px;">
						查看其他答案 <input class="getId" type="hidden" value="${question.id}" />
					</div>
					<div class="othA" id="otherA${question.id}" style="display: none;">
						<c:forEach var="answer" items="${question.answerses}">
							<c:if test="${answer.state!='审核通过'}">
								<span>${answer.content}</span>→→→→→→答案<span>${answer.state}</span>
								<br />
							</c:if>
						</c:forEach>
					</div>
				</c:if>
				<hr style="height: 1px; color: red" />
			</c:forEach>
		</div>
	</div>
	<div class="pageNum">
		<input id="nowpage" type="hidden" style="display: none"
			value="${nowPage} " />
		<c:if test="${totalcount!=0 }">
			<c:if test="${not empty totalcount}">
				<span style="color: #999999;">找到相关的结果${totalcount}条,${maxPage}页,搜索共耗时：${time}秒</span>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			</c:if>
			<div class="pagination">
				<ul>
					<li><a id="firstpage" rel="0" href="javascript:void(0)">首页</a>
					</li>
					<li><a id="before" href="javascript:void(0)">上一页</a></li>
					<c:forEach var="pagenum" items="${pagenum}">
						<li><a class="pagenum" rel="${pagenum}"
							href="javascript:void(0)">${pagenum}</a></li>
					</c:forEach>
					<li><a id="next" href="javascript:void(0)">下一页</a></li>
					<li><a id="lastpage" rel="${maxPage-1}"
						href="javascript:void(0)">尾页</a></li>
				</ul>
			</div>
		</c:if>
	</div>
</body>
<script type="text/javascript">
/*<div class="questionT" id="questiontypes${questionTypes.id}">
				<input type="hidden" value="${questionTypes.id}"/>
				类型${status.count}:
				<a class="expansionBtn" title="点击展开" 
					id="expansionTypeBtn${questionTypes.id}" href="javascript:viod(0)">＋</a>
				<a class="intoQuestionType" title="点击进入问题类型页" href="gotoquestiontype.action?questionTypesId=${questionTypes.id}">${questionTypes.name}</a><br/>
				<div id="questionOf${questionTypes.id}" style="float: none;">
					<c:forEach var="question" items="${questionTypes.questions}">
						<c:forEach var="files" items="${question.questionFilesRels}">
							文件名:${files.filename}
						</c:forEach>
					</c:forEach>
				</div>
			</div>*/
	//文件分类的部分
	$(function(){
		$(".questionT").each(function(){
			var typeId = $(this).children("input[type='hidden']").val();
			$(this).children(".expansionBtn").toggle(function(){
				$("#questionOf"+typeId).css("display","block");
				$("#expansionTypeBtn"+typeId).text("－");
				//$(this).children(".fileses").css("display","block");
			},function(){
				$("#expansionTypeBtn"+typeId).text("＋");
				$("#questionOf"+typeId).css("display","none");
			});
			
		});
		$(".openOrExpansion").toggle(function(){
			$(".fileses").css("display","none");
			$(".expansionBtn").text("＋");
			$(this).text("┗");
		},function(){
			$(".fileses").css("display","block");
			$(".expansionBtn").text("－");
			$(this).text("┏");
			
		});
	});


	$(function() {
		$(".delQuestionById").css("cursor", "pointer");
		$(".delQuestionById").each(function(){
			var questionId = $(this).children(".hiddenQuestionId").val();
			//alert(questionId);
			$("#delQuest"+questionId).click(function() {
				//alert(questionId);
				
				var r = confirm("您确定要删除该问题及相关答案文件吗?");
				if(r==true){
					$.post("deleteQuestionById.action", {"questionId" : questionId}, function(data) {
						window.location.replace(true);
						window.location.replace(true);
						/*window.location.replace(true);
						confirm("删除成功！");*/
					});
				}else {
					return false;
				}
			});
		});
	});
	function showTimer() {
		var mydate = new Date();
		var text = mydate.toLocaleString();
		var div = document.getElementById("timer");
		div.innerHTML = text;
		setTimeout("showTimer()", 1000);
	}
	window.onload = showTimer();

	$(function() {
		$(".filetypeName").hover(function() {
			$(this).css("color", "blue");
		});
	});
	$(function() {
		$(".stackOne").each(function() {
			var quesId = $(this).children(".getId").val();
			//alert(quesId);
			$("#otherAnswer" + quesId).hover(function() {
				$(this).css("text-decoration", "underline");
			}, function() {
				$(this).css("text-decoration", "none");
			});
			$("#otherAnswer" + quesId).toggle(function() {
				$(this).siblings("#otherA" + quesId).css("display", "block");
			}, function() {
				$(this).siblings("#otherA" + quesId).css("display", "none");
			});

		});

	});

	//添加按钮的验证
	function getVerifyUser() {
		//$.get("getUser.action",);

		$.get("addquestion.action", function(data) {
			if (data == false) {
				//alert("您还没登陆!");
				$(".logintishi").text("您还没登陆,转向登录中....");
				setTimeout(function tiaozhuan() {
					window.location.href = "login.action?task=askQuestion";
				}, 3000);
				return false;
			} else if (data == true) {//有用户session，跳转
				window.location.href = "addQuestionWithUser.action";
			}
		});
	}
	$(function() {
		/*$(".filetypeName").each(
			function() {
				var filetypeId = $(this).children("input").val();
				//alert("文件夹名字："+filetypeId);
				$("#firstStackFiletype" + filetypeId).toggle(
					function() {
						//alert(filetypeId);
						$("#firstStackFiletype" + filetypeId
										+ ":first-child").text("┳");
						$("#secondstack" + filetypeId).css("display",
								"block");
					},
					function() {
						$("#firstStackFiletype" + filetypeId
										+ ":first-child").text("┣");
						$("#secondstack" + filetypeId).css("display",
								"none");
					});
		});*/

		$("input[name='searchQuestion']").click(function() {
			$(this).val("");
			$(this).css("color", "#5B5B5B");
		});

		$(".searchButton").click(function() {
			if ($("input[name='searchQuestion']").val() == "请输入关键词"||$("input[name='searchQuestion']").val()=="") {
				$(this).siblings(".nullOfTishi").text("您还没输入...");
				$(this).siblings(".nullOfTishi").css("color","red");
				setTimeout(function hiddenTishi(){
					$(".nullOfTishi").text("");
					
				},3000);
				$(this).fadeIn(3000);
				return false;
			}
			$("form[class='searchForm']").submit();
		});
	});

	$(function() {
		$("#before").click(function() {
			//alert($("#searchQuestion").val());
			var nowP = parseInt($("#nowpage").val());
			if (nowP == 0) {
				return false;
			}
			nowP = nowP - 1;
			if (nowP < 0) {
				nowP = 0;
			}
			window.location.href = "index.action?nowPage=" + nowP;
		});
		$("#next").click(function() {
			var nextP = parseInt($("#nowpage").val());
			if (nextP == $("#lastpage").attr("rel")) {
				return false;
			}
			var m = parseInt($("#lastpage").attr("rel"));
			nextP = nextP + 1;
			if (nextP > m) {
				nextP = m;
			}
			window.location.href = "index.action?nowPage=" + nextP;
		});

		$(".pagenum").click(
				function() {
					//alert($(this).attr("rel"));
					var page = $(this).attr("rel");
					if (parseInt(page) == (parseInt($("#nowpage").val()) + 1)) {
						return false;
					}
					window.location.href = "index.action?nowPage="
							+ (parseInt(page) - 1);
				});

		$("#firstpage").click(
			function() {
				if (parseInt($("#nowpage").val()) == ($("#firstpage").attr("rel"))) {
					return false;
				}
				window.location.href = "index.action?nowPage="
						+ $("#firstpage").attr("rel");
				$("#firstpage").parent().addClass("active");
			});
		$("#lastpage").click(
				function() {
					if (parseInt($("#nowpage").val()) == ($("#lastpage")
							.attr("rel"))) {
						return false;
					}
					$("#hiddensearchname").val();
					window.location.href = "index.action?nowPage="
							+ $("#lastpage").attr("rel");
		});
	});
</script>
</html>
